package com.dhcc.core.framework.result.node;

import java.io.Serializable;

import com.dhcc.core.config.properties.SysProperties;
import com.dhcc.core.framework.util.PinyinUtil;
import com.dhcc.core.framework.util.SpringContextHolder;

/**
 * jquery ztree 插件的节点
 * 
 * @ClassName: ZTreeNode
 * @Description: TODO
 * @author: cyf
 * @date: 2018年1月2日 上午9:30:09
 */
public class ZTreeNode implements Serializable{

    /**
     * @fieldName: serialVersionUID
     * @fieldType: long
     * @Description: TODO
     */
    private static final long serialVersionUID = 1L;

    private Long id; // 节点id

    private Long pId;// 父节点id

    private String name;// 节点名称

    private Boolean open;// 是否打开节点

    private Boolean checked;// 是否被选中

    private Boolean isParent;// 是否父节点

    private Boolean nocheck=false;// 是否可选

    private String pinyin;//拼音全拼

    private String initials;//拼音首拼

    private String iconSkin;//图标

    public String getIconSkin() {
        return iconSkin;
    }

    public void setIconSkin(String iconSkin) {
        this.iconSkin = iconSkin;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getpId() {
        return pId;
    }

    public void setpId(Long pId) {
        this.pId = pId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getOpen() {
        return open;
    }

    public void setOpen(Boolean open) {
        this.open = open;
    }

    public Boolean getIsOpen() {
        return open;
    }

    public void setIsOpen(Boolean open) {
        this.open = open;
    }

    public Boolean getChecked() {
        return checked;
    }

    public void setChecked(Boolean checked) {
        this.checked = checked;
    }

    public Boolean getIsParent() {
        return isParent;
    }

    public void setIsParent(Boolean isParent) {
        this.isParent = isParent;
    }

    public Boolean getNocheck() {
        return nocheck;
    }

    public void setNocheck(Boolean nocheck) {
        this.nocheck = nocheck;
    }

    public String getPinyin() {
        return pinyin;
    }

    public void setPinyin(String pinyin) {
        this.pinyin = pinyin;
    }

    public String getInitials() {
        return initials;
    }

    public void setInitials(String initials) {
        this.initials = initials;
    }

    public static ZTreeNode createNode(Long id,Long pId,String name) {
        ZTreeNode zTreeNode = new ZTreeNode();
        zTreeNode.setChecked(false);
        zTreeNode.setId(id);
        zTreeNode.setName(name);
        zTreeNode.setIsOpen(true);
        zTreeNode.setIsParent(true);
        zTreeNode.setNocheck(false);
        zTreeNode.setpId(pId);
        zTreeNode.setInitials(PinyinUtil.converterToFirstSpell(name));
        zTreeNode.setPinyin(PinyinUtil.converterToSpell(name));
        return zTreeNode;
    }

    public static ZTreeNode createNode(Long id,String name) {
        return createNode(id,0L,name);
    }

    public static ZTreeNode createRoot(String name) {
        ZTreeNode root = createNode(0L,name);
        root.setNocheck(true);
        root.setIconSkin("org");
        return root;
    }

    public static ZTreeNode createRoot() {
        SysProperties sysProperties = SpringContextHolder.getBean(SysProperties.class);
        return createRoot(sysProperties.getOrgFullName());
    }

    @Override
    public String toString() {
        return "ZTreeNode{" +
                "id=" + id +
                ", pId=" + pId +
                ", name='" + name + '\'' +
                ", open=" + open +
                ", checked=" + checked +
                ", isParent=" + isParent +
                ", nocheck=" + nocheck +
                ", pinyin='" + pinyin + '\'' +
                ", initials='" + initials + '\'' +
                ", iconSkin='" + iconSkin + '\'' +
                '}';
    }
}
